extends Node


#region 移动相关
@export_subgroup("移动输入配置")
@export var move_left_input_event: String = "Move_Left"
@export var move_right_input_event: String = "Move_Right"


#上次的移动速度
var lastMvSpeed: float = 0;

#当前的移动速度
var curMvSpeed: float = 0;


#移动事件
signal move_input_sig(delta, iptValue)


#停止移动事件
signal move_stop_sig()


#endregion


#region  跳跃相关属性
@export_subgroup("跳跃输入配置")
@export var jump_input_event: String = "Jump"


var once_jump_count: int = 0;

#跳跃输入事件
signal jump_sig()

#跳跃输入取消事件
signal not_jump_sig()

#endregion


#region 连招攻击相关属性

@export_subgroup("连招输入配置")
@export var combo_input_event: String = "Combo"

signal combo_sig()

signal not_combo_sig()
#endregion


#region 生命周期

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	update_move_event(delta)
	update_jump_event(delta)
	update_combo_event(delta)


#endregion


#region  移动相关方法

#更新移动的事件信息
func update_move_event(deltatime: float) -> void:
	#获取横向输入的值
	curMvSpeed = Input.get_axis(move_left_input_event, move_right_input_event)
	
	if (abs(curMvSpeed) > 0):
		#print("移动ing")
		move_input_sig.emit(deltatime, curMvSpeed)
	else:
		if (abs(lastMvSpeed) > 0):
			#print("停止移动了")
			move_stop_sig.emit()
	lastMvSpeed = curMvSpeed

#endregion


#region 跳跃相关方法

func update_jump_event(deltatime: float) -> void:
	if Input.is_action_just_pressed((jump_input_event)) || Input.is_action_pressed(jump_input_event):
		once_jump_count = +1
		if (once_jump_count == 1):
			jump_sig.emit()
	elif (Input.is_action_just_released((jump_input_event))):
		once_jump_count = 0
		not_jump_sig.emit()

#endregion


#更新连招事件
func update_combo_event(deltatime: float) -> void:
	if (Input.is_action_just_pressed((combo_input_event)) || Input.is_action_pressed(combo_input_event)):
		combo_sig.emit()
	if (Input.is_action_just_released((combo_input_event))):
		not_combo_sig.emit()
